package com.ww.springboot.dd.amazon;

import org.springframework.lang.NonNull;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author wuhuiqiang
 * @Description mws站点枚举
 * @Date 2020/10/27 11:50
 **/
public enum MwsMarketplace {

    US("US", "ATVPDKIKX0DER", "https://mws.amazonservices.com", "USD"),

    CA("CA", "A2EUQ1WTGCTBG2", "https://mws.amazonservices.ca", "CAD"),

    BR("BR", "A2Q3Y263D00KWC", "https://mws.amazonservices.com", "BRL"),

    MX("MX", "A1AM78C64UM0Y8", "https://mws.amazonservices.com.mx", "MXN"),

    UK("UK", "A1F83G8C2ARO7P", "https://mws-eu.amazonservices.com", "GBP"),

    FR("FR", "A13V1IB3VIYZZH", "https://mws-eu.amazonservices.com", "EUR"),

    DE("DE", "A1PA6795UKMFR9", "https://mws-eu.amazonservices.com", "EUR"),

    IT("IT", "APJ6JRA9NG5V4", "https://mws-eu.amazonservices.com", "EUR"),

    ES("ES", "A1RKKUPIHCS9HS", "https://mws-eu.amazonservices.com", "EUR"),

    TR("TR", "A33AVAJ2PDY3EV", "https://mws-eu.amazonservices.com", ""),

    JP("JP", "A1VC38T7YXB528", "https://mws.amazonservices.jp", "JPY"),

    SG("SG", "A19VAU5U5O7RUS", "https://mws-fe.amazonservices.com", "SGD"),

    IN("IN", "A21TJRUUN4KGV", "https://mws.amazonservices.in", "INR"),

    AU("AU", "A39IBJ37TRP1C6", "https://mws.amazonservices.com.au", "AUD"),

    AE("AE", "A2VIGQ35RCS4UG", "https://mws.amazonservices.ae", "AED"),

    NL("NL", "A1805IZSGTT6HS", "https://mws-eu.amazonservices.com", "EUR"),

    PL("PL", "A1C3SOZRARQ6R3", "https://mws-eu.amazonservices.com", "PLN"),

    SA("SA", "A17E79C6D8DWNP", "https://mws-eu.amazonservices.com", "SAR"),

    EG("EG", "ARBP9OOSHTCHU", "https://mws-eu.amazonservices.com", "EGP"),

    SE("SE", "A2NODRKZP88ZB9", "https://mws-eu.amazonservices.com", "SEK"),

    CN("CN", "AAHKV2X7AFYLW", "https://mws.amazonservices.com.cn", "RMB");

    private static Map<String, MwsMarketplace> valueMap = new HashMap<>(32);

    static {
        for (MwsMarketplace item : MwsMarketplace.values()) {
            valueMap.put(item.getMarketplaceId(), item);
        }
    }

    MwsMarketplace(String siteCode, String marketplaceId, String endpoint, String currency) {
        this.siteCode = siteCode;
        this.marketplaceId = marketplaceId;
        this.endpoint = endpoint;
        this.currency = currency;
    }

    private String siteCode;
    /**
     * 站点id
     */
    private String marketplaceId;

    /**
     * 端点接口地址
     */
    private String endpoint;

    /**
     * 币种
     */
    private String currency;

    public String getMarketplaceId() {
        return marketplaceId;
    }

    public String getEndpoint() {
        return endpoint;
    }

    public String getSiteCode() {
        return siteCode;
    }

    public String getCurrency() {
        return currency;
    }

    /**
     * @Author wuhuiqiang
     * @Description 根据 marketplaceId 获取MwsMarketplace
     * @Date 2020/10/27 11:51
     **/
    public static MwsMarketplace of(String marketplaceId) {
        return valueMap.get(marketplaceId);
    }

    public static MwsMarketplace getMwsMarketplaceBySite(@NonNull String siteCode){
        for (MwsMarketplace value : MwsMarketplace.values()) {
            if (value.getSiteCode().equalsIgnoreCase(siteCode)){
                return value;
            }
        }
        return null;
    }
}
